﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using WebApiCoreDemo.Common;
using WebApiCoreDemo.Model;

namespace WebApiCoreDemo.Api.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class StudentController : ControllerBase
    {
        [HttpGet]
        public Student Get()
        {
            NlogUtil.WriteInfo(MethodBase.GetCurrentMethod().DeclaringType.FullName, "NlogUtil写普通日志", "data数据", "WebApiCoreDemo.Api");
            NlogUtil.WriteError(MethodBase.GetCurrentMethod().DeclaringType.FullName, "NlogUtil写异常日志", "data数据", new Exception("自定义异常内容"), "WebApiCoreDemo.Api");
            return new Student() { Id = 1, Name = "ZhangSan" };
        }

        /// <summary>
        /// 获取地址信息
        /// </summary>
        /// <param name="address">地址</param>
        /// <returns></returns>
        [HttpGet]
        public ResponseResult GetAddress(string address)
        {
            //1、返回值为string类型，前台dataType必须是text
            //return "address=" + address;
            //2、返回值为JsonResult类型，前台dataType可以是text、json
            //return new JsonResult("address=" + address);
            //3、返回值为自定义类型，前台dataType可以是text、json
            return new ResponseResult() { Success = true, Data = "address=" + address };
        }

        [HttpPost]
        public string Post([FromForm]Student student, [FromForm]ResponseResult result, int basic1, string basic2)//, int basic1, string basic2
        {
            return "Post(), student.id=" + student.Id + ", student.name=" + student.Name;
        }
    }
}